<template>
	<view style="position: relative;">
		
		<view class="" v-if="page_type=='yqm'">
			<image :src="qrimg" style="width: 100%;z-index: 1;" mode="widthFix"></image>
			<view style="width: 230upx;border-radius: 100upx;background-color: #ccc;color: #fff;text-align: center;line-height: 100upx;height: 100upx;position: fixed;bottom: 140upx;right: 80upx;z-index: 99;font-weight: 555;font-size: 32upx;" @click="saveImgToLocal">
				保存图片
			</view>
		</view>
		<view class="" v-if="page_type=='fxxys'">
			这是风险提示协议书页面
		</view>
		<view class="" v-if="page_type=='fwxy'">
			这是用户服务协议页面
		</view>
		<view class="" v-if="page_type=='ysxy'">
			这是用户隐私协议页面
		</view>
		<view class="" v-if="page_type== undefined">
			<image :src="qrimg" style="width: 100%;z-index: 1;" mode="widthFix"></image>
			<view style="width: 230upx;border-radius: 100upx;background-color: #ccc;color: #fff;text-align: center;line-height: 100upx;height: 100upx;position: fixed;bottom: 140upx;right: 80upx;z-index: 99;font-weight: 555;font-size: 32upx;" @click="saveImgToLocal">
				保存图片
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				qrimg:'',
				openid:'',
				mid:'',
				page_type:''
			};
		},
		onLoad:function(e){
			console.log(e.type);
			if(e.type== 'fxxys'){
				uni.setNavigationBarTitle({// 修改头部标题
				    title: '风险提示协议书'
				});
			}
			if(e.type == 'fwxy'){
				uni.setNavigationBarTitle({// 修改头部标题
				    title: '服务协议'
				});
				
			}
			if(e.type == 'ysxy'){
				uni.setNavigationBarTitle({// 修改头部标题
				    title: '用户隐私协议'
				});
			}
			if(e.type == undefined || e.type=='yqm'){
				uni.setNavigationBarTitle({// 修改头部标题
				    title: '分享码'
				});
			}
			this.page_type=e.type
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					uni.getStorage({
						key: 'mid',
						success: (res) => {
							this.mid = res.data
							this.setAjax()
						},
						fail: () => {
							uni.navigateTo({
								url: '../../login/login'
							});
						}
					});
				},
				fail: () => {
					uni.navigateTo({
						url: '../../login/login'
					});
				}
			});
		},
		methods:{
			saveImgToLocal(){
				uni.downloadFile({
						url: this.qrimg,//图片地址
						success: (res) =>{
							console.log(res)
								if (res.statusCode === 200){
										uni.saveImageToPhotosAlbum({
												filePath: res.tempFilePath,
												success: function() {
														uni.showToast({
																title: "保存成功",
																icon: "none"
														});
												},
												fail: function() {
														uni.showToast({
																title: "保存失败",
																icon: "none"
														});
												}
										});
								} 
						}
				})
			},
			setAjax(){
				// uni.request({
				// 	url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=commission.qrcode&app=1',
				// 	method: 'POST',
				// 	data: {'openid':this.openid,'mid':this.mid},
				// 	header:{'Content-Type':'application/x-www-form-urlencoded'},
				// 	success: res => {
				// 		console.log(res)
				// 		uni.hideLoading()
				// 		if (res.data.error ==1) {
				// 			uni.showToast({
				// 				title: res.data.message,
				// 				mask: false,
				// 				duration: 1500
				// 			});
				// 			return
				// 		}
				// 		// this.qrimg = res.data.result.img
				// 	},
				// 	fail: () => {},
				// 	complete: () => {}
				// });
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=commission.qrcode&app=1',
					method: 'POST',
					data: {'openid':this.openid,'mid':this.mid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						console.log(res)
						uni.hideLoading()
						if (res.data.error ==1) {
							uni.showToast({
								title: res.data.message,
								mask: false,
								duration: 1500
							});
							return
						}
						console.log(res.data)
						this.qrimg = res.data.result.img
						// this.qrimg = res.data.result.img
					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>.tips{background:#fff;padding:16upx 24upx;border-bottom:1px solid #f0f0f0;}.tips .title{width:84upx;margin-right:24upx;color:#000;}.tips .cont{color:#666;}</style>
